//
//  BuyCarViewController.m
//  Car
//
//  Created by 何晓文 on 15/10/4.
//  Copyright © 2015年 朱鸿儒. All rights reserved.
//

#import "BuyCarViewController.h"
#define kBuyCarURL @"http://car.m.yiche.com/gouchejisuanqi/"
@interface BuyCarViewController ()<UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *web;
@end

@implementation BuyCarViewController


- (void)viewDidLoad {
	
	NSURL *url = [NSURL URLWithString:kBuyCarURL];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
	self.web = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
	[self.web loadRequest:request];
	
	[super viewDidLoad];
	self.web.delegate = self;
	
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}
//开始加载网页
- (void)webViewDidStartLoad:(UIWebView *)webView {
	[ProgressHUD show:@"正在加载请稍后"];
	self.web.alpha = 0;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
	//删除header
	NSMutableString *js0 = [NSMutableString string];
	[js0 appendString:@"var post = document.getElementsByClassName('header')[0];"];
	[js0 appendString:@"post.parentNode.removeChild(post);"];
	[webView stringByEvaluatingJavaScriptFromString:js0];
	
	//删除下载按钮
	NSMutableString *js1 = [NSMutableString string];
	[js1 appendString:@"var post = document.getElementsByClassName('m-fixed-app-download')[0];"];
	[js1 appendString:@"post.parentNode.removeChild(post);"];
	[webView stringByEvaluatingJavaScriptFromString:js1];
	//删除下载背景
	NSMutableString *js2 = [NSMutableString string];
	[js2 appendString:@"var post = document.getElementsByClassName('m-fixed-app-mask')[0];"];
	[js2 appendString:@"post.parentNode.removeChild(post);"];
	[webView stringByEvaluatingJavaScriptFromString:js2];
	[ProgressHUD showSuccess:nil];
	self.view = self.web;
	[UIView animateWithDuration:0.5 animations:^{
		self.web.alpha = 1;
	}];
	
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
	[ProgressHUD showError:@"加载失败"];

}
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:YES];
	[ProgressHUD dismiss];
	
}
@end
